//
//  XLTitleTextFieldCell.m
//  industry
//
//  Created by xl on 2020/12/10.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLTitleTextFieldCell.h"

@interface XLTitleTextFieldCell ()

@property (nonatomic, strong) XLTextField *textField;
@property (nonatomic, strong) XLLabel *titleLB;
@property (nonatomic, strong) XLView *lineView;

@end
@implementation XLTitleTextFieldCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLB];
        [self.contentView addSubview:self.textField];
        [self.contentView addSubview:self.lineView];
        
        [self makeConstraints];
    }
    return self;
}

- (void)makeConstraints {
    [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(20);
        make.left.equalTo(self.contentView).offset(30);
    }];
    
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLB);
        make.right.equalTo(self.contentView).offset(-30);
        make.top.equalTo(self.titleLB.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLB);
        make.right.equalTo(self.textField);
        make.bottom.equalTo(self.textField);
        make.height.mas_equalTo(1);
    }];
}

#pragma mark - Public
- (void)loadCellData:(NSString *)title
             content:(NSString *)content
         placeholder:(NSString *)placeholder {
    _titleLB.text = title;
    _textField.placeholder = placeholder;
    _textField.text = content;
}

- (void)setCurrentSecurity:(BOOL)status {
    _textField.secureTextEntry = status;
}

#pragma mark - TextField
- (void)textFieldContentChange:(XLTextField *)sender {
    if (self.TextFieldBlock) {
        self.TextFieldBlock(sender.text);
    }
}

#pragma mark - Setter/getter
- (XLLabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [XLLabel new];
        _titleLB.font = [UIFont fontOfPingFangSCSemiboldWithSize:15];
        _titleLB.textColor = [UIColor blackFontColor];
    }
    return _titleLB;
}

- (XLTextField *)textField {
    if (!_textField) {
        _textField = [XLTextField new];
        _textField.font = [UIFont fontOfPingFangSCRegularWithSize:14];
        _textField.textColor = [UIColor blackFontColor];
        [_textField setCurrentTextFiledCanPaste:NO];
        
        [_textField addTarget:self action:@selector(textFieldContentChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _textField;
}

- (XLView *)lineView {
    if (!_lineView) {
        _lineView = [XLView new];
        _lineView.backgroundColor = [UIColor graySecondLineColor];
    }
    return _lineView;
}
@end
